fix(onsen): Handle numeric delivery_date from API#3
Merged
Conversation
The application crashes with a JSON unmarshaling error when processing
data from a paid member session. This is caused by the `delivery_date`
field, which is expected to be a "MM/DD" string, sometimes being sent
as a number (e.g., 23744) for older episodes accessible to paid members.
This commit fixes the crash and correctly handles both data types by
implementing a prioritized date-finding strategy, preserving the
original logic's structure.
1. The `delivery_date` field in the `nuxt.Content` struct is changed to
`interface{}` to accept both strings and numbers, preventing the
initial crash.
2. The `Episodes()` method is augmented to be type-aware, following a
strict priority for determining an episode's date:
- **Priority 1**: If `delivery_date` is a string, the original,
preferred `GuessTime` logic is used.
- **Last Resort**: If `delivery_date` is a number, a new helper
function, `dateFromURL`, is called to parse the full date from
the episode's `streaming_url` filename. This is only used when
the string date is not present.
3. The initial "anchor-finding" loop is also made type-safe to avoid
errors when processing episodes with numeric dates.
This resolves the bug for paid sessions by correctly parsing dates from
the streaming URL as a fallback, while ensuring the original guessing
logic is preserved for all other cases, preventing regressions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The application crashes with a JSON unmarshaling error when processing data from a paid member session. This is caused by the
delivery_datefield, which is expected to be a "MM/DD" string, sometimes being sent as a number (e.g., 23744) for older episodes accessible to paid members.This commit fixes the crash and correctly handles both data types by implementing a prioritized date-finding strategy, preserving the original logic's structure.
The
delivery_datefield in thenuxt.Contentstruct is changed tointerface{}to accept both strings and numbers, preventing the initial crash.The
Episodes()method is augmented to be type-aware, following a strict priority for determining an episode's date:delivery_dateis a string, the original, preferredGuessTimelogic is used.delivery_dateis a number, a new helper function,dateFromURL, is called to parse the full date from the episode'sstreaming_urlfilename. This is only used when the string date is not present.The initial "anchor-finding" loop is also made type-safe to avoid errors when processing episodes with numeric dates.
This resolves the bug for paid sessions by correctly parsing dates from the streaming URL as a fallback, while ensuring the original guessing logic is preserved for all other cases, preventing regressions.